package com.cloudrui.service.wechat.neteasy;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.cloudrui.service.wechat.neteasy.bean.MsgComparable;
import com.cloudrui.service.wechat.neteasy.bean.OneMsg;

public class MsgService {
	private List<OneMsg> currentMsgs;
	
	public List<OneMsg> getLatestMsgs(List<OneMsg>newMsgs){
		List<OneMsg>latestOne = new ArrayList<OneMsg>();
		if(currentMsgs == null) {
			currentMsgs =  newMsgs;
			return newMsgs;
		}else {
			for(OneMsg msg:newMsgs) {
				if(currentMsgs.contains(msg)) {
					continue;
				}else {
					latestOne.add(msg);
				}
			}
			currentMsgs =  newMsgs;
		}
		
		Collections.sort(latestOne, new MsgComparable());
		Collections.reverse(latestOne);
		return latestOne;
	}

	public List<OneMsg> getCurrentMsgs() {
		return currentMsgs;
	}

	public void setCurrentMsgs(List<OneMsg> currentMsgs) {
		this.currentMsgs = currentMsgs;
	}
}
